package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos =new FileOutputStream("pw1.txt");//这是换行写出的底层逻辑,不做日常使用
        OutputStreamWriter osw =new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter bw =new BufferedWriter(osw);
        PrintWriter pw =new PrintWriter(bw,true);
        //因为构造器的参数是(高级流,boolean),所以前三层不能省
        //简化版的构造器为(File filename)

        Scanner scan =new Scanner(System.in);
        while(true){
            String line =scan.nextLine().trim();
            if ("exit".equals(line)){
                break;
            }
            pw.write(line);
        }
        System.out.println("输出完毕");
        pw.close();
    }
}
